import Axios from 'axios'
import { Loading } from 'element-ui';

const configBaseURL = "/yakeikea"

const axios = Axios.create({
    // baseURL: process.env.VUE_APP_BASE_URL,
    baseURL: configBaseURL,
    timeout: 10000
})
let Load
axios.interceptors.request.use(config => {
    // console.log(config)
    let token = JSON.parse(sessionStorage.getItem("token"))
    token && (config.headers["token"] = token)
    Load = Loading.service({ text: "玩命加载中~" })
    return config
}, error => Promise.reject(error))

axios.interceptors.response.use(response => {
    // response.data.token && sessionStorage.setItem("token", response.data.token)
    Load.close()
    return response.data
}, error => {
    let res = error.response
    if (res.status === 401) {
        sessionStorage.removeItem("token")
    }
    return Promise.reject(error)
})


export default axios